﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows;

namespace Learn001.Controls
{
    [TemplatePart(Name = PanelDescript, Type = typeof(TextBlock))]
    public class BlackPanel : CustomPanel
    {
        protected internal const string PanelDescript = "txtDescript";
        protected internal TextBlock txtDescript;

        public static readonly DependencyProperty TitleDescriptProperty =
            DependencyProperty.Register("TitleDescript", typeof(string), typeof(BlackPanel), new PropertyMetadata("", new PropertyChangedCallback(TitleDescriptChanged)));

        public string TitleDescript
        {
            get { return (string)GetValue(TitleDescriptProperty); }
            set { SetValue(TitleDescriptProperty, value); }
        }

        private static void TitleDescriptChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            BlackPanel panel = sender as BlackPanel;
            if (panel == null) return;

            if (e.NewValue != null && panel.txtDescript != null)
                panel.txtDescript.Text = e.NewValue.ToString();
            else if (panel.txtDescript != null)
                panel.txtDescript.Text = "";
        }

        public BlackPanel()
            : base()
        {
            this.DefaultStyleKey = typeof(BlackPanel);
        }

        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            txtDescript = base.GetTemplateChild(PanelDescript) as TextBlock;

            if (txtDescript != null)
                txtDescript.Text = TitleDescript;
        }

    }
}
